
using System;
using ABasile;
using System.Web.UI;
using System.Text;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;


namespace webpman
{
	/// <summary>
	/// Description of General.
	/// </summary>
	public class General
	{
				
		public string UserLanguage = "";
        public string PageSkin = "";
		public ABasile.ResourceReader RMan;
		public ABasile.ResourceReader RCMan;
		private DBManager DBMan;
		
		private ABasile.Utility Uman = new Utility();
		private string DBpath;
		private StreamReader SRMan;
		private NameValueCollection SELECTCOMMAND = new NameValueCollection();



		
		public General()
		{

			#region SELECT COMMANDS
			
			#region SELECT project
			SELECTCOMMAND["project"] = 		
				"SELECT " +
					"T_PROJECT.T_PROJECT_ID AS ID, " +
					"T_PROJECT.T_PROJECT_NAME AS NAME, " +
					"(SELECT SUM((T_TASK_WEIGHT * T_TASK_COMPLETE) / 100)  FROM T_TASK WHERE T_TASK.T_PROJECT_ID = T_PROJECT.T_PROJECT_ID) AS CP, " + 
					"strftime(\"%Y-%m-%d %H:%M\", T_PROJECT.T_PROJECT_STARTDATE) AS START, " +
					"strftime(\"%Y-%m-%d %H:%M\", T_PROJECT.T_PROJECT_ENDDATE) AS END, " +
					"strftime(\"%Y-%m-%d %H:%M\", T_PROJECT.T_PROJECT_ESTENDDATE) AS PREV_END, " +
					"(julianday(date(T_PROJECT.T_PROJECT_ESTENDDATE)) - julianday(date('now')) ) AS D," +
					"T_PROJECT.T_PROJECT_ACTIVE AS ACTIVE, " +
					"T_USER.T_USER_ACCOUNT AS LEADER, " +
					"T_CATEGORY.T_CATEGORY_NAME AS CATEGORY, " +
					"T_STATE.T_STATE_NAME AS STATE  " +
				"FROM " +
					"T_PROJECT, " +
					"T_CATEGORY, " +
					"T_USER, " +
					"T_STATE " +
				"WHERE " +
					"T_PROJECT.T_CATEGORY_ID = T_CATEGORY.T_CATEGORY_ID AND " +
					"T_PROJECT.T_STATE_ID = T_STATE.T_STATE_ID AND " +
					"T_PROJECT.T_USER_ID = T_USER.T_USER_ID "; 
			#endregion SELECT project
			
			#region SELECT authuser
			SELECTCOMMAND["authuser"] = 
				"SELECT " + 
					"T_AUTH.T_AUTH_ID AS ID, " +
					"T_USER.T_USER_ACCOUNT AS ACCOUNT, " +
					"T_USER.T_USER_REALNAME AS NAME, " +
					"T_USER.T_USER_GROUP AS USERGROUP, " +
					"T_USER.T_USER_DESCRIPTION AS DESCRIPTION, " +
					"T_AUTH.T_AUTH_TYPE AS TYPE " +
				"FROM " +
					"T_USER, " +
					"T_AUTH " +
				"WHERE " +
					"T_USER.T_USER_ID = T_AUTH.T_USER_ID AND " +
					"T_AUTH.T_PROJECT_ID = <!-- project --> ";
			#endregion SELECT authuser
			
			#region SELECT task
			SELECTCOMMAND["task"] =
				"SELECT " + 
					"T_TASK.T_TASK_ID AS ID, " +
					"T_TASK.T_TASK_NAME AS NAME, " +
					"T_TASK.T_TASK_COMPLETE AS CP, " +
					"strftime(\"%Y-%m-%d %H:%M\", T_TASK.T_TASK_STARTDATE) AS START, " +
					"strftime(\"%Y-%m-%d %H:%M\", T_TASK.T_TASK_ENDDATE) AS END, " +
					"strftime(\"%Y-%m-%d %H:%M\", T_TASK.T_TASK_ESTENDDATE) AS PREV_END, " +
					"(julianday(date(T_TASK.T_TASK_ESTENDDATE)) - julianday(date('now')) ) AS D," +
					"T_TASK.T_TASK_ACTIVE AS ACTIVE, " +
					"T_USER.T_USER_ACCOUNT AS LEADER, " +
					"T_CATEGORY.T_CATEGORY_NAME AS CATEGORY, " +
					"T_STATE.T_STATE_NAME AS STATE,  " +
					"T_TASK.T_TASK_WEIGHT AS W, " +
					"T_PROJECT.T_PROJECT_NAME AS PROJECT " +
				"FROM " +
					"T_TASK, " +
					"T_USER, " +
					"T_CATEGORY, " +
					"T_STATE, " +
					"T_PROJECT " +
				"WHERE " +
					"T_TASK.T_CATEGORY_ID = T_CATEGORY.T_CATEGORY_ID AND " +
					"T_TASK.T_STATE_ID = T_STATE.T_STATE_ID AND " +
					"T_TASK.T_USER_ID = T_USER.T_USER_ID AND " +
					"T_TASK.T_PROJECT_ID = T_PROJECT.T_PROJECT_ID " +
					"";
			#endregion SELECT task
			
			#region SELECT item
			SELECTCOMMAND["item"] =
				"SELECT " + 
					"T_ITEM.T_ITEM_ID AS ID, " +
					"T_ITEM.T_ITEM_NAME AS NAME, " +
					"strftime(\"%Y-%m-%d %H:%M\", T_ITEM.T_ITEM_INSDATE) AS DATEINS, " +
					"T_USER.T_USER_ACCOUNT AS USER, " +
					"T_TASK.T_TASK_NAME AS TASK, " +
					"T_STATE.T_STATE_NAME AS STATE,  " +
					"T_ITEM.T_ITEM_DESCRIPTION AS DESCRIPTION " +
				"FROM " +
					"T_TASK, " +
					"T_USER, " +
					"T_ITEM, " +
					"T_STATE " +
				"WHERE " +
					"T_ITEM.T_TASK_ID = T_TASK.T_TASK_ID AND " +
					"T_ITEM.T_STATE_ID = T_STATE.T_STATE_ID AND " +
					"T_ITEM.T_USER_ID = T_USER.T_USER_ID " +
					"";
			#endregion SELECT item
			
			#region SELECT category
			SELECTCOMMAND["category"] = 
				"SELECT " + 
					"T_CATEGORY.T_CATEGORY_ID AS ID, " +
					"T_CATEGORY.T_CATEGORY_NAME AS NAME, " +
					"T_CATEGORY.T_CATEGORY_APPLYTO AS APPLYTO " +
				"FROM " +
					" T_CATEGORY ";
			#endregion SELECT category
			
			#region SELECT state
			SELECTCOMMAND["state"] =
				"SELECT " + 
					"T_STATE.T_STATE_ID AS ID, " +
					"T_STATE.T_STATE_NAME AS NAME, " +
					"T_STATE.T_STATE_APPLYTO AS APPLYTO " +
				"FROM " +
					" T_STATE ";
			#endregion SELECT state
			
			#region SELECT user
			SELECTCOMMAND["user"] =
				"SELECT " + 
					"T_USER.T_USER_ID AS ID, " +
					"T_USER.T_USER_ACCOUNT AS ACCOUNT, " +
					"T_USER.T_USER_REALNAME AS REALNAME, " +
					"T_USER.T_USER_DESCRIPTION AS DESCRIPTION, " +
					"T_USER.T_USER_GROUP AS USERGROUP, " +
					"T_USER.T_USER_TYPE AS TYPE, " +					
					"T_USER.T_USER_ACTIVE AS ACTIVE, " +
					"T_USER.T_USER_RSSID AS RSSID " +
				"FROM " +
					"T_USER ";
			#endregion SELECT user

			#region SELECT REPORT project
			SELECTCOMMAND["reportproject"] = 		
				"SELECT " +
					"T_PROJECT.T_PROJECT_ID AS ID, " +
					"T_PROJECT.T_PROJECT_NAME AS NAME, " +
					"(SELECT SUM((T_TASK_WEIGHT * T_TASK_COMPLETE) / 100)  FROM T_TASK WHERE T_TASK.T_PROJECT_ID = T_PROJECT.T_PROJECT_ID) AS CP, " + 
					"strftime(\"%Y-%m-%d %H:%M\", T_PROJECT.T_PROJECT_STARTDATE) AS START, " +
					"strftime(\"%Y-%m-%d %H:%M\", T_PROJECT.T_PROJECT_ENDDATE) AS END, " +
					"strftime(\"%Y-%m-%d %H:%M\", T_PROJECT.T_PROJECT_ESTENDDATE) AS PREV_END, " +
					"(julianday(date(T_PROJECT.T_PROJECT_ESTENDDATE)) - julianday(date('now')) ) AS D," +
					"T_PROJECT.T_PROJECT_ACTIVE AS ACTIVE, " +
					"T_PROJECT.T_PROJECT_DESCRIPTION AS DESCRIPTION, " +
					"T_PROJECT.T_PROJECT_NOTES AS OTHER, " +
					"T_USER.T_USER_ACCOUNT AS LEADER, " +
					"T_CATEGORY.T_CATEGORY_NAME AS CATEGORY, " +
					"T_STATE.T_STATE_NAME AS STATE  " +
				"FROM " +
					"T_PROJECT, " +
					"T_CATEGORY, " +
					"T_USER, " +
					"T_STATE " +
				"WHERE " +
					"T_PROJECT.T_CATEGORY_ID = T_CATEGORY.T_CATEGORY_ID AND " +
					"T_PROJECT.T_STATE_ID = T_STATE.T_STATE_ID AND " +
					"T_PROJECT.T_USER_ID = T_USER.T_USER_ID "; 
			#endregion SELECT REPORT project

			#region SELECT REPORT task
			SELECTCOMMAND["reporttask"] = 		
				"SELECT " +
					"T_TASK.T_TASK_ID AS ID, " +
					"T_TASK.T_TASK_NAME AS NAME, " +
					"T_TASK.T_TASK_COMPLETE AS CP, " + 
					"strftime(\"%Y-%m-%d %H:%M\", T_TASK.T_TASK_STARTDATE) AS START, " +
					"strftime(\"%Y-%m-%d %H:%M\", T_TASK.T_TASK_ENDDATE) AS END, " +
					"strftime(\"%Y-%m-%d %H:%M\", T_TASK.T_TASK_ESTENDDATE) AS PREV_END, " +
					"(julianday(date(T_TASK.T_TASK_ESTENDDATE)) - julianday(date('now')) ) AS D," +
					"T_TASK.T_TASK_ACTIVE AS ACTIVE, " +
					"T_TASK.T_TASK_DESCRIPTION AS DESCRIPTION, " +
					"T_TASK.T_TASK_NOTES AS OTHER, " +
					"T_USER.T_USER_ACCOUNT AS LEADER, " +
					"T_CATEGORY.T_CATEGORY_NAME AS CATEGORY, " +
					"T_STATE.T_STATE_NAME AS STATE,  " +
					"T_TASK.T_TASK_WEIGHT AS WEIGHT " +
				"FROM " +
					"T_TASK, " +
					"T_CATEGORY, " +
					"T_USER, " +
					"T_STATE " +
				"WHERE " +
					"T_TASK.T_CATEGORY_ID = T_CATEGORY.T_CATEGORY_ID AND " +
					"T_TASK.T_STATE_ID = T_STATE.T_STATE_ID AND " +
					"T_TASK.T_USER_ID = T_USER.T_USER_ID "; 
			#endregion SELECT REPORT task

			#region SELECT REPORT item
			SELECTCOMMAND["reportitem"] = 		
				"SELECT " +
					"T_ITEM.T_ITEM_ID AS ID, " +
					"T_ITEM.T_ITEM_NAME AS NAME, " +
					"T_ITEM.T_ITEM_COMPLETE AS CP, " + 
					"T_ITEM.T_ITEM_INSDATE AS START, " +
					"T_ITEM.T_ITEM_DESCRIPTION AS DESCRIPTION, " +
					"T_USER.T_USER_ACCOUNT AS LEADER, " +
					"T_STATE.T_STATE_NAME AS STATE  " +
				"FROM " +
					"T_ITEM, " +
					"T_USER, " +
					"T_STATE " +
				"WHERE " +
					"T_ITEM.T_STATE_ID = T_STATE.T_STATE_ID AND " +
					"T_ITEM.T_USER_ID = T_USER.T_USER_ID "; 
			#endregion SELECT REPORT item

			#endregion SELECT COMMANDS
			
		}
		
		
		
		
		
		public void SetEnvironment(ref Page thePage)
        {
        	// read configuration skin
			PageSkin = System.Web.Configuration.WebConfigurationManager.AppSettings["pageskin"];
			
			// add link to ref. css 
        	((master1)thePage.Master).MPHeader.Controls.Add(Uman.GetCssLink("skins/" + PageSkin + "/general.css"));
			
        	// update language
			if (thePage.Request.Cookies["lang"] == null)
			{
				thePage.Response.Redirect("updater.aspx?lang=en-US&callpage=default.aspx");
				return;
			}
			
            UserLanguage = thePage.Request.Cookies["lang"].Value;
            
            // Set Resource Manager
			RMan = new ResourceReader(thePage.Server.MapPath("~/lang_resources"),"common",UserLanguage);
			
			// Set Custom Resource Manager
			RCMan = new ResourceReader(thePage.Server.MapPath("~/skins/" + PageSkin),"custom","");
			
			// Update DBpath 
			DBpath = System.Web.Configuration.WebConfigurationManager.AppSettings["dbpath"];
			if (DBpath == null)
				DBpath = thePage.Server.MapPath("~/db/webpman.sqlite");
			else
				DBpath = thePage.Server.MapPath(DBpath);
        }

		
		
		public string GetTemplatePage(string TemplatePath)
		{
			try
			{
				string TemplateContent;
				SRMan = new StreamReader(TemplatePath);
				TemplateContent = SRMan.ReadToEnd();
				SRMan.Close();
				SRMan.Dispose();
				SRMan = null;
				return TemplateContent;
			}
			catch (Exception Ex)
			{
				return "<!-- Template Page Error: " + Ex.Message + " -->";
			}
		}
		
		
		
		public void DBOpen()
		{
			DBMan = new DBManager(DBpath);
		}
		

		
		public void DBClose()
		{
			
			DBMan.Close();
		}

		
		
		public string DBUserCheck(string Uname, string Upassword)
		{
			// 
			return DBMan.CheckUser(Uname, Upassword);
		}


		
		public bool UserAuthorization(string uname, string usertype, string tableobject, string tableID, string operationtype)
		{
			
			string AuthType = "";
			
			// If Administrator then ALL PERMISSIONS
			if (usertype == "A")
				return true;
			
			// Access to system table only to administrator
			if (((tableobject == "user") ||
			     (tableobject == "state") ||
			     (tableobject == "category") ||
			     (tableobject == "authuser")) &&
			     usertype != "A")
				return false;
			
			// only administrators can add projects
			if ((tableobject == "project") && 
			    (usertype != "A") && 
			    (operationtype == "A"))
				return false;
			
			
			AuthType = DBMan.CheckAuthProject(uname, tableobject, tableID);
			
			// If only view
			if (operationtype == "V")
			{
				if (AuthType != "")
					return true;
				else
					return false;
			}

			// If delete
			if (operationtype == "D")
			{
				AuthType = DBMan.CheckAuthProject(uname, tableobject, tableID);
				
				if ((tableobject == "item") && (AuthType != ""))
					return true;
				
				if (((tableobject == "task") || (tableobject == "item")) && (AuthType == "P"))
					return true;
				
				// default
				return false;
			}
			

			// If modify
			if (operationtype == "M")
			{
				AuthType = DBMan.CheckAuthProject(uname, tableobject, tableID);
				
				if ((tableobject == "item") && (AuthType == "P"))
					return true;
				
				if ((tableobject == "task") && (AuthType == "P"))
					return true;
				
//				if ((tableobject == "project") && (AuthType != "P"))
//					return true;

				// default
				return false;
			}
			

			// If add
			if (operationtype == "A")
			{
				
				if (tableobject == "item")
				{
					AuthType = DBMan.CheckAuthProject(uname, "task", tableID);
					if (AuthType != "") 
						return true;
					else
						return false;
				}
					
				if (tableobject == "task")
				{
					AuthType = DBMan.CheckAuthProject(uname, "project", tableID);
					if (AuthType == "P") 
						return true;
					else
						return false;
				}
				
			}

			
			// default
			return false;
			
		}
		
		
		
		public string DBGetTable(string webpman_object, string Order, string MyAccount, string MyAuth,  NameValueCollection QString)
		{
			// Create Table to return
			string sqlcmdtext = "";
			string TableOutput = "";
			int colnumber = 0;			
			string MyRssid = "";
			string PageNumber = "1";
			string ItemForPage = System.Web.Configuration.WebConfigurationManager.AppSettings["itemsperpage"];

			if (QString["page"] != null)
			{
				if (QString["page"].Trim() != "")
					PageNumber = QString["page"];
			}		
			
			
			#region Prepare Sql Command
			
			if (webpman_object == "project")
				sqlcmdtext = SELECTCOMMAND[webpman_object];
			else if (webpman_object == "task")
			{
				sqlcmdtext = SELECTCOMMAND[webpman_object];
				if (QString["pid"] != null)					
					if(QString["pid"].Trim() != "") sqlcmdtext += " AND T_PROJECT.T_PROJECT_ID = " + QString["pid"];
			}
			else if (webpman_object == "item")
			{
				sqlcmdtext = SELECTCOMMAND[webpman_object];
				if (QString["pid"] != null)
					if(QString["pid"].Trim() != "") sqlcmdtext += " AND T_TASK.T_TASK_ID = " + QString["pid"];
			}
			else if (webpman_object == "category")
				sqlcmdtext = SELECTCOMMAND[webpman_object];
			else if (webpman_object == "state")
				sqlcmdtext = SELECTCOMMAND[webpman_object];
			else if (webpman_object == "user")
				sqlcmdtext = SELECTCOMMAND[webpman_object];
			else if (webpman_object == "authuser")
			{
				if (QString["pid"] == null)
					return Uman.GetErrorMessage(RMan.GetString("missingparameter"));
				
				if (QString["pid"].Trim() == "")
					return Uman.GetErrorMessage(RMan.GetString("missingparameter"));
				
				sqlcmdtext = SELECTCOMMAND[webpman_object].Replace("<!-- project -->", QString["pid"]);
			}
			else
				sqlcmdtext = SELECTCOMMAND["project"];


			if (webpman_object == "project" && Order == "")
				Order = "START ASC";
			else if (webpman_object == "task" && Order == "")
				Order = "T_TASK_STARTDATE ASC";
			else if (webpman_object == "item" && Order == "")
				Order = "T_ITEM_INSDATE ASC";
			else if (webpman_object == "category" && Order == "")
				Order = "T_CATEGORY_NAME ASC";
			else if (webpman_object == "state" && Order == "")
				Order = "T_STATE_NAME ASC";
			else if (webpman_object == "user" && Order == "")
				Order = "T_USER_ACCOUNT ASC";
			else if (webpman_object == "authuser" && Order == "")
				Order = "ACCOUNT ASC";
			else if (Order == "")
				Order = "T_PROJECT_STARTDATE ASC";

			sqlcmdtext+=" ORDER BY " + Order;

			sqlcmdtext+=" LIMIT " + 
				((int.Parse(ItemForPage) * int.Parse(PageNumber)) - int.Parse(ItemForPage)).ToString() + 
					"," + 
					int.Parse(ItemForPage).ToString();
			
			#endregion Prepare Sql Command

			
			// Debug
			// Uman.AppendTraceFile("General.cs", "DBGetTable", sqlcmdtext + "\n" + ItemForPage + "\n" + PageNumber);
			
			// Retrieve data from Database
			ArrayList MyData = DBMan.GetRecordset(sqlcmdtext);
						
			
			// Create Headers of table
			List<string> headdata = new List<string>( Uman.GetStringByObject( ((object[])MyData[0]) ));
			
			
			// Update Headers of table
			switch (webpman_object)
			{
				case "project":
					headdata.Insert(3, "$COMPLETED");
					break;

				case "task":
					headdata.Insert(3, "$COMPLETED");
					break;
				
				default:
					break;
			}
				
			
			// Update page client javascripts
			TableOutput=GetTemplatePage(Uman.GetPath("~/javascripts/delete_function.js")).Replace("<!-- deletemessage -->", RMan.GetString("deletemessage"));
			
			
			// Init Result table
			TableOutput+="<div style=\"height:25px\"></div><div align=\"center\">";
			TableOutput+="<table id=\"reporttable\" class=\"ReportTable\" >";
			TableOutput+="<tr><td colspan=\"<!-- columncount -->\">";
			TableOutput+="<table id=\"titletable\" class=\"TitleTable\" ><tr>";
			TableOutput+="<td class=\"TitleCell\" align=\"left\">" + RMan.GetString("title" + webpman_object) + "</td>";
			TableOutput+="<td align=\"right\">";
			
			if(webpman_object != "item" && webpman_object != "task")
				TableOutput+="<a style=\"text-decoration:none;\" href=\"modify.aspx?object=" + webpman_object + "\"><span class=\"AddItemCell\">" + RMan.GetString("addbutton") + "</span>&nbsp;<img border=\"0\" src=\"skins/" + PageSkin + "/images/add.png\" /></a>";
			
			TableOutput+="</td>";
			TableOutput+="</tr></table>";
			TableOutput+="</td></tr>";
			
			
			// Add table header row
			colnumber = headdata.Count - 1;
			TableOutput+="<tr>";
			for (int n=1; n<headdata.Count; n++)
			{
				if (headdata[n] != "AUTH")
				{
					if (headdata[n].Substring(0,1) == "$")
					{
						// Add column WITHOUT sort function
						TableOutput+="<td align=\"center\" class=\"ReportTopCell\">" + headdata[n].Substring(1);							
					}
					else
					{
						// // Add column WITH sort function
						TableOutput+="<td align=\"center\" class=\"ReportTopCell\">" + headdata[n].ToString() + "&nbsp;&nbsp;" + 
							"<a style=\"text-decoration:none\" href=\"default.aspx?object=" + webpman_object + "&order=" + headdata[n].ToString() + " ASC&pid=" + Convert.ToString(QString["pid"]) + "\"><img border=\"0\" src=\"" + 
								"skins/" + PageSkin + "/images/asc.png" + "\"/></a>" +
		                    "<a style=\"text-decoration:none\" href=\"default.aspx?object=" + webpman_object + "&order=" + headdata[n].ToString() + " DESC&pid=" + Convert.ToString(QString["pid"]) + "\"><img border=\"0\" src=\"" + 
								"skins/" + PageSkin + "/images/desc.png" + "\"/></a>";
					}
				}
			}
			
			
			// Add Header buttons space (modify, delete buttons)
			TableOutput+="<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>" +						 
						 "<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>";
			colnumber+=2;
			
			// Add custom table header cells
			switch (webpman_object)
			{
				case "project":
					TableOutput+="<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>" + 
						         "<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>" +
						 		 "<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>" +
						 		 "<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>" +
								 "<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>" ;
					colnumber+=4;
					break;

				case "task":
					TableOutput+="<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>" + 
					             "<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>" +
						 		 "<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>" +
						         "<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>";
					colnumber+=3;
					break;
				
				case "item":
					TableOutput+="<td width=\"22\" align=\"center\" class=\"ReportTopCell\">&nbsp;</td>";
					colnumber+=1;
					break;

				default:
					break;
			}

			
			// Close tag for header row
			TableOutput+="</tr>";
			
			
			// Loop for fill body of table
			for (int j=1; j<MyData.Count; j++)
			{
				// Create array of row data
				List<string> rowdata = new List<string>( Uman.GetStringByObject( ((object[])MyData[j]) ));
				
				//if (UserAuthorization(MyAccount, MyAuth, webpman_object, rowdata[0], "V") == true)
				//{
				
				#region ADD ROW WITH DATA
				
					// Update Row data for custom info
					switch (webpman_object)
					{
						case "project":						
							rowdata.Insert(3, Uman.GetGraph(rowdata[2])); 		// Add % project completed
							break;
						
						case "task":						
							rowdata.Insert(3, Uman.GetGraph(rowdata[2])); 		// Add % task completed
							break;
						
						default:
							break;
					}
					
					
					// Add tag row
					TableOutput+="<tr class=\"ReportRow\">";
					
					
					// Loop for row data
					for (int k=1; k<rowdata.Count; k++)
					{
						if (headdata[k] != "AUTH")
						{
							TableOutput+="<td ";
							
							// Align graphic object to left
							if(headdata[k] == "$COMPLETED")
								TableOutput+="align=\"left\" class=\"ReportInnerCell\">" + rowdata[k] + "</td>";
							else if ((webpman_object == "project" || webpman_object == "task") &&
						    	(k == 7) && (rowdata[11] == "ended"))
								TableOutput+="align=\"center\" class=\"ReportInnerCell\">&nbsp;</td>";
							else
								TableOutput+="align=\"center\" title=\"" + rowdata[k] + "\" class=\"ReportInnerCell\">" + rowdata[k].PadRight(22).Substring(0,22) + "&nbsp;</td>";
							
						}
					}
					
					// 
					TableOutput+="<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("deletebutton") +"\" href=\"javascript:delete_item('" + webpman_object + "','" + Convert.ToString(rowdata[0]) + "');\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/del.png\" /></a></td>" +
								 "<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("modifybutton") +"\" href=\"modify.aspx?object=" + webpman_object + "&pid=" + Convert.ToString(rowdata[0]) + "\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/mod.png\" /></a></td>";
	
					
					// custom table body buttons
					switch (webpman_object)
					{
						case "project":
							MyRssid = DBMan.GetRssId(MyAccount);
							TableOutput+="<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("usersbutton") +"\" href=\"default.aspx?object=authuser&pid=" + Convert.ToString(rowdata[0]) + "\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/auth.png\" /></a></td>" +
			 							 "<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("tasksbutton") +"\" href=\"default.aspx?object=task&pid=" + Convert.ToString(rowdata[0]) + "\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/go.png\" /></a></td>" + 
							             "<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("details") +"\" href=\"report.aspx?object=project&pid=" + Convert.ToString(rowdata[0]) + "\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/view.png\" /></a></td>" + 
										 "<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("addtaskbutton") +"\" href=\"modify.aspx?object=task&refid=" + Convert.ToString(rowdata[0]) + "\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/add.png\" /></a></td>" +
										 "<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("rssbutton") +"\" href=\"rss.aspx?o=project&id=" + Convert.ToString(rowdata[0]) + "&rssid=" + MyRssid + "\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/rss.png\" /></a></td>";
							break;
						
						case "task":
							MyRssid = DBMan.GetRssId(MyAccount);
							TableOutput+="<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("itemsbutton") +"\" href=\"default.aspx?object=item&pid=" + Convert.ToString(rowdata[0]) + "\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/go_item.png\" /></a></td>" + 
						                 "<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("details") +"\" href=\"report.aspx?object=toptask&pid=" + Convert.ToString(rowdata[0]) + "\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/view.png\" /></a></td>" + 
								         "<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("additembutton") +"\" href=\"modify.aspx?object=item&refid=" + Convert.ToString(rowdata[0]) + "\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/add.png\" /></a></td>" + 
										 "<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("rssbutton") +"\" href=\"rss.aspx?o=task&id=" + Convert.ToString(rowdata[0]) + "&rssid=" + MyRssid + "\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/rss.png\" /></a></td>";
							break;

						case "item":
							TableOutput+="<td align=\"center\" class=\"ReportInnerCell\"><a title=\"" + RMan.GetString("details") +"\" href=\"report.aspx?object=item&pid=" + Convert.ToString(rowdata[0]) + "\"><img border=\"0\" src=\"skins/" + PageSkin + "/images/view.png\" /></a></td>";							
							break;

						default:
							break;
					}
	
					
					// Close tag for body row
					TableOutput+="</tr>";
				
				
				#endregion ADD ROW WITH DATA
				
				//} // End If Check User Authorization
			}

			// Add bottom button for next page
			if (MyData.Count == (int.Parse(ItemForPage) + 1))
			{
				QString["page"] = (int.Parse(PageNumber) + 1).ToString();
				
				TableOutput+="<tr><td align=\"right\" colspan=\"<!-- columncount -->\">" +
					"<a style=\"text-decoration:none;\" href=\"default.aspx?" + QString.ToString();
				TableOutput+="\"><span class=\"AddItemCell\">" + RMan.GetString("nextpage") +
					"</span>&nbsp;<img border=\"0\" src=\"skins/" + PageSkin + "/images/next.png\" /></a></td></tr>";
			}
			
			// Close tag for table
			TableOutput+="</table></div>";

			
			// Add bottom space
			TableOutput+="<div style=\"height:40px\"></div>";
			TableOutput = TableOutput.Replace("<!-- columncount -->", colnumber.ToString());
			
			
			return TableOutput;
		}

		
		
		public string DBDelete(string webpman_object, string MyAccount, string MyAuth, NameValueCollection QString)
		{
			// Delete record from table
			string sqlcmdtext = "";
			
			if (QString["pid"] == null)
				return Uman.GetErrorMessage(RMan.GetString("missingparameter"));
			
			if (QString["pid"].Trim() == "")
				return Uman.GetErrorMessage(RMan.GetString("missingparameter"));

			// Check authorization
			if (UserAuthorization(MyAccount, MyAuth, webpman_object, QString["pid"], "D") == false)
				return Uman.GetErrorMessage(RMan.GetString("notauthorized"));
			
			
			#region Prepare Sql Delete Command
			
			if (webpman_object == "project")
				sqlcmdtext = "DELETE FROM T_PROJECT WHERE T_PROJECT.T_PROJECT_ID = " + QString["pid"];
			else if (webpman_object == "task")
				sqlcmdtext = "DELETE FROM T_TASK WHERE T_TASK.T_TASK_ID = " + QString["pid"];
			else if (webpman_object == "item")
				sqlcmdtext = "DELETE FROM T_ITEM WHERE T_ITEM.T_ITEM_ID = " + QString["pid"];
			else if (webpman_object == "category")
				sqlcmdtext = "DELETE FROM T_CATEGORY WHERE T_CATEGORY.T_CATEGORY_ID = " + QString["pid"];
			else if (webpman_object == "state")
				sqlcmdtext = "DELETE FROM T_STATE WHERE T_STATE.T_STATE_ID = " + QString["pid"];
			else if (webpman_object == "user")
				sqlcmdtext = "DELETE FROM T_USER WHERE T_USER.T_USER_ID = " + QString["pid"];
			else if (webpman_object == "authuser")
				sqlcmdtext += "DELETE FROM T_AUTH WHERE T_AUTH.T_AUTH_ID = " + QString["pid"];
			else
				return Uman.GetErrorMessage(RMan.GetString("missingparameter"));

			#endregion Prepare Sql Delete Command
			

			
			// Debug
			// Uman.AppendTraceFile("General.cs", "DBDelete", sqlcmdtext);
			
			string RetDelete = DBMan.ExecSQL(sqlcmdtext);
			if (RetDelete != "")
				return Uman.GetErrorMessage(RetDelete);
			else
				return RetDelete;
			
		}

	
	
		public string DBEditTable(string webpman_object, string MyAccount, string MyAuth, NameValueCollection QString)
		{
			// Edit tabel record
			string recordid = "";
			string refrecordid = "";
			string TableOutput = "";
			bool ModifyAction = false;
			string	tablename = "";
			
			#region Prepare tablename
			
			if (webpman_object == "project")
				tablename = "T_PROJECT";
			else if (webpman_object == "task")
				tablename = "T_TASK";
			else if (webpman_object == "item")
				tablename = "T_ITEM";
			else if (webpman_object == "category")
				tablename = "T_CATEGORY";
			else if (webpman_object == "state")
				tablename = "T_STATE";
			else if (webpman_object == "user")
				tablename = "T_USER";
			else if (webpman_object == "authuser")
				tablename = "T_AUTH";
			else
				return Uman.GetErrorMessage(RMan.GetString("missingparameter"));

			if (QString["pid"] != null)
			{
				if (QString["pid"].Trim() != "")
					recordid = QString["pid"].ToString();
			}
			
			// Reference record of parent object
			if (QString["refid"] != null)
			{
				if (QString["refid"].Trim() != "")					
					refrecordid = QString["refid"].ToString();
			}
			
			#endregion Prepare tablename
			
			
			
			
			// Retrieve data from Database
			ArrayList MyData = DBMan.GetTableData(tablename, recordid);

			
			
			// Create filed name list
			List<string> FieldName = new List<string>( Uman.GetStringByObject( ((object[])MyData[0])) );
			List<string> FieldValue = new List<string>();
			
			// Add table reference to form
			TableOutput+="<input runat=\"server\" type=\"hidden\" id=\"TABLENAME\" name=\"TABLENAME\" value=\"" + tablename + "\" >\n";
			
			
			if (MyData.Count == 2)
			{
				ModifyAction = true;

				// Update hidden info with record id
				TableOutput+="<input runat=\"server\" type=\"hidden\" id=\"RECORDID\" name=\"RECORDID\" value=\"" + recordid + "\" >\n";
				TableOutput+="<input runat=\"server\" type=\"hidden\" id=\"OPERATION\" name=\"OPERATION\" value=\"MODIFY\" >\n";

				// Create filed value list
				FieldValue = new List<string>( Uman.GetStringByObject( ((object[])MyData[1]) ));
			}
			else
			{
				TableOutput+="<input runat=\"server\" type=\"hidden\" id=\"OPERATION\" name=\"OPERATION\" value=\"INSERT\" >\n";
			}
			
			
			// Init Result table
			TableOutput+="<div style=\"height:25px\"></div><div align=\"center\">";
			TableOutput+="<table width=\"700\" id=\"reporttable\" class=\"ReportTable\" >";
			TableOutput+="<tr><td class=\"TitleCell\" align=\"left\" colspan=\"2\">";
			TableOutput+=RMan.GetString("edit" + webpman_object) + "</td></tr>";			

			// Fill Edit area
			for (int k=0; k<FieldName.Count; k++)
			{
				TableOutput+="<tr>\n";
				
				// Add Field Name
				TableOutput+="<td align=\"right\" valign=\"top\" class=\"EditCellName\">\n&nbsp;&nbsp;" + RMan.GetString(FieldName[k]);
				TableOutput+="</td>\n";
				
				// Add Field Value
				TableOutput+="<td align=\"left\" valign=\"top\" class=\"EditCellValue\">\n";
				
				// Update html code for specific field
				if (ModifyAction == true)
					TableOutput+=Uman.GetFieldEditCode(tablename, FieldName[k], FieldValue[k], ref DBMan, MyAccount, refrecordid) +
						"&nbsp;" + Uman.GetMandatoryChars(tablename, FieldName[k]);
				else
					TableOutput+=Uman.GetFieldEditCode(tablename, FieldName[k], "", ref DBMan, MyAccount, refrecordid) + 
						"&nbsp;" + Uman.GetMandatoryChars(tablename, FieldName[k]);
				
				
				TableOutput+="&nbsp;</td>\n";
				
				// Close row tag
				TableOutput+="</tr>\n";
			}
			
			// Add submit button
			TableOutput+="<tr><td colspan=\"2\" align=\"center\" height=\"40\"><input class=\"ButtonText1\" type=\"button\" name=\"cmdmodify\" value=\"" + RMan.GetString("applymodify") + "\" id=\"cmdmodify\" onclick=\"submit();\" /></td></tr>\n";
			
			// Close table tag
			TableOutput+="</table>";
			
			return TableOutput;			
		}
	
		
		
		public string DBUpdateTable(string webpman_object, string MyAccount, string MyAuth, NameValueCollection FormObject)
		{
			string OutData = "";
			string sqltextcommand = "";
			bool okupdate = false;
			
			if (FormObject["OPERATION"] == "INSERT")
			{
				// Check authorization
				if (webpman_object == "project")
					okupdate = UserAuthorization(MyAccount, MyAuth, webpman_object, "", "A");
				else if (webpman_object == "task")
					okupdate = UserAuthorization(MyAccount, MyAuth, webpman_object, FormObject["T_PROJECT_ID"], "A");
				else if (webpman_object == "item")
					okupdate = UserAuthorization(MyAccount, MyAuth, webpman_object, FormObject["T_TASK_ID"], "A");
				else
					okupdate = UserAuthorization(MyAccount, MyAuth, webpman_object, "", "A");
				
				if (!okupdate)
					return Uman.GetErrorMessage(RMan.GetString("notauthorized"));
				
				
				// INSERT
				sqltextcommand = "INSERT INTO " + FormObject["TABLENAME"] + " (";
				
				// ADD fieldnames to sql command
				for (int h=0; h<FormObject.Count; h++)
				{
					if (FormObject.GetKey(h).Substring(0,2).ToUpper() == "T_")
						sqltextcommand+=FormObject.GetKey(h) + ", ";
				}
				
				if (FormObject["TABLENAME"] == "T_USER")
					sqltextcommand+="T_USER_RSSID, ";
				
				sqltextcommand = sqltextcommand.Substring(0, sqltextcommand.Length-2);				
				sqltextcommand+= ") VALUES ( ";

				// ADD fieldvalues to sql command
				for (int h=0; h<FormObject.Count; h++)
				{
					if (FormObject.GetKey(h).Substring(0,2).ToUpper() == "T_")
						sqltextcommand+=Uman.GetFieldUpdateCode(FormObject.GetKey(h), FormObject[h]) + ", ";
				}
				
				if (FormObject["TABLENAME"] == "T_USER")
					sqltextcommand+="'" + Uman.RandomString(8,false) + "', ";
				
				sqltextcommand = sqltextcommand.Substring(0, sqltextcommand.Length-2);
				sqltextcommand+= ")";
			}
			else
			{
				// Check authorization
				if (UserAuthorization(MyAccount, MyAuth, webpman_object, FormObject["RECORDID"], "M") == false)
					return Uman.GetErrorMessage(RMan.GetString("notauthorized")); 
				
				// UPDATE
				sqltextcommand = "UPDATE " + FormObject["TABLENAME"] + " SET ";

				// ADD fields name and value to sql command
				for (int h=0; h<FormObject.Count; h++)
				{
					if (FormObject.GetKey(h).Substring(0,2).ToUpper() == "T_")
					{
						sqltextcommand+=FormObject.GetKey(h) + 
							" = " + 
							Uman.GetFieldUpdateCode(FormObject.GetKey(h), FormObject[h]) + ", ";
					}						
				}				
				
				sqltextcommand = sqltextcommand.Substring(0, sqltextcommand.Length-2);
				sqltextcommand+= " WHERE " + FormObject["TABLENAME"] + "_ID = " + FormObject["RECORDID"];
				
			}
			
			// Insert/Update database
			OutData = DBMan.ExecSQL(sqltextcommand);

			// Debug
			Uman.AppendTraceFile("General.cs", "DBUpdateTable", sqltextcommand);
			
			if (OutData != "")
				return Uman.GetErrorMessage(OutData);

			//Update Task by Item changes
			if (FormObject["TABLENAME"] == "T_ITEM")
			{
				sqltextcommand = "UPDATE T_TASK SET " + 
					"T_TASK_COMPLETE = " + FormObject["T_ITEM_COMPLETE"] + ", " +
					"T_STATE_ID = " + FormObject["T_STATE_ID"] + " " +
					"WHERE T_TASK_ID = " + FormObject["T_TASK_ID"];
				
				OutData = DBMan.ExecSQL(sqltextcommand);
				
				if (OutData != "")
					return Uman.GetErrorMessage(OutData);
			}
			
			return Uman.GetInfoMessage("Ok");			
			
		}
		
	
	
		public string DBGetReport(string webpman_object, string RecordID, string MyAccount, string MyAuth)
		{
			// Return detailed report 
			string sqlcmdtext = "";
			string OutData = "";

			
			if (webpman_object == "project")
				sqlcmdtext = SELECTCOMMAND["reportproject"] + 
					" AND T_PROJECT.T_PROJECT_ID = " + RecordID + 
					" ORDER BY T_PROJECT.T_PROJECT_STARTDATE ASC";
			else if (webpman_object == "task")
				sqlcmdtext = SELECTCOMMAND["reporttask"] + 
					" AND T_TASK.T_PROJECT_ID = " + RecordID + 
					" ORDER BY T_TASK.T_TASK_STARTDATE ASC";
			else if (webpman_object == "toptask")
			{
				sqlcmdtext = SELECTCOMMAND["reporttask"] + 
					" AND T_TASK.T_TASK_ID = " + RecordID + 
					" ORDER BY T_TASK.T_TASK_STARTDATE ASC";
				webpman_object = "task";
			}
			else if (webpman_object == "item")
				sqlcmdtext = SELECTCOMMAND["reportitem"] + 
					" AND T_ITEM.T_TASK_ID = " + RecordID +
					" ORDER BY T_ITEM.T_ITEM_INSDATE ASC";
			else
				return Uman.GetErrorMessage(RMan.GetString("missingparameter"));

			
			// Debug
			// Uman.AppendTraceFile("General.cs","DBGetReport",sqlcmdtext);
			
			// Retrieve data from Database
			ArrayList MyData = DBMan.GetRecordset(sqlcmdtext);
			
			
			if (MyData.Count < 2)
				return "";
				
			List<string> reportdata;

			if (webpman_object == "project")
			{
				reportdata = new List<string>( Uman.GetStringByObject( ((object[])MyData[1]) ));
				OutData = "<div style=\"height:35px\"></div><table class=\"RepTable\">\n" +
					"<tr><td class=\"RepCel\">" + RMan.GetString("reportproject") + ": <b>" +
						reportdata[1] + "</b></td><td class=\"RepCel\" colspan=\"4\"><em>" + reportdata[8] + "</em></td></tr>\n" +
					"<tr><td class=\"RepCel\">" + RMan.GetString("reportstate") + ": " + reportdata[12] + "</td>\n" + 
						"<td class=\"RepCel\">" + RMan.GetString("reportstart") + ": " + reportdata[3] + "</td>\n" +
						"<td class=\"RepCel\">" + RMan.GetString("reportdelta") + ": " + reportdata[6] + "</td>\n" +
						"<td class=\"RepCel\">" + RMan.GetString("reportprev") + ": " + reportdata[5] + "</td>\n" +
						"<td class=\"RepCel\">" + RMan.GetString("reportend") + ": " + reportdata[4] + "</td></tr>\n" +
					"<tr><td class=\"RepCel\">" + RMan.GetString("reportperc") + ": " + reportdata[2] + "</td>\n" + 
						"<td class=\"RepCel\" colspan=\"2\">" + RMan.GetString("reportcategory") + ": " + reportdata[11] + "</td>\n" +
						"<td class=\"RepCel\">" + RMan.GetString("reportleader") + ": " + reportdata[10] + "</td>\n" +
						"<td class=\"RepCel\">" + RMan.GetString("reportactive") + ": " + reportdata[7] + "</td></tr>\n" +						
					"<tr><td class=\"RepCel\" colspan=\"5\">" + RMan.GetString("reportnotes") + ": <em>" + reportdata[9] + "</em></td></tr>\n" +
					"</table>\n" +
					"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td width=\"40\"></td><td>\n" +
						DBGetReport("task",reportdata[0],MyAccount,MyAuth) + 
					"\n</td></tr></table>\n";
			}
			else if (webpman_object == "task")
			{
				for (int j=1; j<MyData.Count; j++)
				{
					reportdata = new List<string>( Uman.GetStringByObject( ((object[])MyData[j]) ));
					OutData+= "<div style=\"height:25px\"></div><table class=\"RepTableT\">\n" +
						"<tr><td class=\"RepCel\">" + RMan.GetString("reporttask") + ": <b>" +
							reportdata[1] + "</b></td><td class=\"RepCel\" colspan=\"4\"><em>" + reportdata[8] + "</em></td></tr>\n" +
						"<tr><td class=\"RepCel\">" + RMan.GetString("reportstate") + ": " + reportdata[12] + "</td>\n" + 
							"<td class=\"RepCel\">" + RMan.GetString("reportstart") + ": " + reportdata[3] + "</td>\n" +
							"<td class=\"RepCel\">" + RMan.GetString("reportdelta") + ": " + reportdata[6] + "</td>\n" +
							"<td class=\"RepCel\">" + RMan.GetString("reportprev") + ": " + reportdata[5] + "</td>\n" +
							"<td class=\"RepCel\">" + RMan.GetString("reportend") + ": " + reportdata[4] + "</td></tr>\n" +
						"<tr><td class=\"RepCel\">" + RMan.GetString("reportperc") + ": " + reportdata[2] + "</td>\n" + 
							"<td class=\"RepCel\" colspan=\"2\">" + RMan.GetString("reportcategory") + ": " + reportdata[11] + "</td>\n" +
							"<td class=\"RepCel\">" + RMan.GetString("reportleader") + ": " + reportdata[10] + "</td>\n" +
							"<td class=\"RepCel\">" + RMan.GetString("reportactive") + ": " + reportdata[7] + "</td></tr>\n" +						
						"<tr><td class=\"RepCel\">" + RMan.GetString("reportweight") + ": " + reportdata[13] + "</td></tr>\n" +
							"<td class=\"RepCel\" colspan=\"4\">" + RMan.GetString("reportnotes") + ": <em>" + reportdata[9] + "</em></td></tr>\n" +
						"</table>\n" +
						"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\"><tr><td width=\"30\"></td><td>\n" +
							DBGetReport("item",reportdata[0],MyAccount,MyAuth) + 
						"\n</td></tr></table>\n";
				}
			}
			else if (webpman_object == "item")
			{
				for (int j=1; j<MyData.Count; j++)
				{
					reportdata = new List<string>( Uman.GetStringByObject( ((object[])MyData[j]) ));
					OutData+= "<div style=\"height:15px\"></div><table class=\"RepTableI\">\n" +
						"<tr><td class=\"RepCel\">" + RMan.GetString("reportitem") + ": <b>" +
							reportdata[1] + "</b></td><td class=\"RepCel\" colspan=\"3\"><em>" + reportdata[4] + "</em></td></tr>\n" +
						"<tr><td class=\"RepCel\">" + RMan.GetString("reportstate") + ": " + reportdata[6] + "</td>\n" + 
							"<td class=\"RepCel\">" + RMan.GetString("reportstart") + ": " + reportdata[3] + "</td>\n" +
							"<td class=\"RepCel\">" + RMan.GetString("reportperc") + ": " + reportdata[2] + "</td>\n" +
							"<td class=\"RepCel\">" + RMan.GetString("reportleader") + ": " + reportdata[5] + "</td>\n" +
							"</tr>\n" +
						"</table>\n";
				}
			}
			else
				OutData = "";



			
			return OutData;
			
		}



		public string DBChangePassword(string MyAccount, string MyNewPassword)
		{
			// Change user password
			string sqlcmdtext = "UPDATE T_USER SET " + 
				"T_USER_PASSWORD = '" + MyNewPassword.Replace("'","''") + "' " + 
					"WHERE T_USER_ACCOUNT = '" + MyAccount.Replace("'","''") + "'";
			
			// Debug
			// Uman.AppendTraceFile("General.cs", "DBDelete", sqlcmdtext);
			
			string RetChange = DBMan.ExecSQL(sqlcmdtext);
			if (RetChange != "")
				return Uman.GetErrorMessage(RetChange);
			else
				return RetChange;
			
		}



		

		
	}
}
